import { queryRuleHome, } from '../services/api';
import { message } from 'antd';
import { isResponerCode } from '../utils/utils';
export default {
  namespace: 'home',

  state: {
    // result: [],
    list: [],
    loading: false,
  },

  effects: {

    *fetch({ payload, callback }, { call, put }) {

      yield put({
        type: 'save',
        payload: {
          loading: true,
        },
      });
      const response = yield call(queryRuleHome, payload);
      // console.log("queryRuleHome", response)
      if (response.result.code != 200) {
        message.error(response.result.message)
      }
      if (response.data) {
        yield put({
          type: 'save',
          payload: {
            list: response.data,
            loading: false,
          },
        });
      }
      if (callback) callback();
    },
  },

  reducers: {//纯函数， 输入什么输出就是什么
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
